import protobuf from 'protobufjs'
export const initProtobuf = async () => {
  try {
    const protoUrl = import.meta.env.Mode === 'development' ? '/signal.proto' : './signal.proto'
    const response = await fetch(protoUrl)
    const content = await response.text()
    const root = await protobuf.parse(content).root
    const MyMessage = root.lookupType('signal.SignalMsg')
    const MsgType = root.lookupEnum('MsgType').values
    return new Promise((resolve) => {
      resolve({
        MyMessage,
        MsgType
      })
    })
  } catch (err) {
    console.log(err)
  }
}
